<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      template="./template/UserTemplate.xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <body>

        <ui:composition template="./template/UserTemplate.xhtml">

            <ui:define name="main_content">
                <h1 class="heading colr">Insert Mark</h1>

                <h:form>
                    <h:panelGrid id="groupPanel" columns="3">

                        <h:panelGrid id="panel" columns="2" cellpadding="5">
                            Curriculum:
                            <h:selectOneMenu  id="curriculum" style="width: 150px;" value="#{marksManagerManagedBean.curriculumId}"
                                              >
                                <f:selectItem itemLabel="Select Curriculum" itemValue="" noSelectionOption="true"/>
                                <f:selectItems var="curriculum" value="${marksManagerManagedBean.listCurriculum}"
                                               itemLabel="${curriculum.curriculumName}"
                                               itemValue="${curriculum.curriculumId}" />
                                <p:ajax async="true" update="semester" />
                            </h:selectOneMenu>

                            Semester:
                            <h:selectOneMenu id="semester" style="width: 150px;"  value="#{marksManagerManagedBean.semesterId}"
                                             >
                                <f:selectItem itemLabel="Select Semester" itemValue="" noSelectionOption="true"/>
                                <f:selectItems var="semester" value="#{marksManagerManagedBean.laySemester(marksManagerManagedBean.curriculumId)}"
                                               itemLabel="${semester.semesterName}"
                                               itemValue="${semester.semesterId}" />
                                <p:ajax async="true" update="panel2" />

                            </h:selectOneMenu>
                        </h:panelGrid>

                        <h:panelGrid id="panel2" columns="2" cellpadding="5">
                            <h:panelGroup>
                                Subject:
                                <h:selectOneMenu id="subject" style="width: 150px;" value="#{marksManagerManagedBean.subjectId}">
                                    <f:selectItem itemLabel="Select Subject" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems var="subject" value="#{marksManagerManagedBean.listSubject}"
                                                   itemLabel="${subject.subjectName}"
                                                   itemValue="${subject.subjectId}" />
                                    <p:ajax async="true" update="examination" />
                                </h:selectOneMenu>

                                Examination:
                                <h:selectOneMenu id="examination" style="width: 150px;" value="#{marksManagerManagedBean.examinationId}" title="Select Examination" rendered="true"
                                                 >
                                    <f:selectItem itemLabel="Select Examination" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems var="examination" value="#{marksManagerManagedBean.listExamination}"
                                                   itemLabel="${examination.examName}"
                                                   itemValue="${examination.examId}" />
                                </h:selectOneMenu>

                            </h:panelGroup>
                            <h:panelGroup>
                                Class:
                                <h:selectOneMenu id="class" style="width: 150px;" value="#{marksManagerManagedBean.classId}" title="Select Class" rendered="true"
                                                 valueChangeListener="#{marksManagerManagedBean.layStudent(marksManagerManagedBean.classId)}">
                                    <f:selectItem itemLabel="Select Class" itemValue="" noSelectionOption="true"/>
                                    <f:selectItems var="class" value="#{marksManagerManagedBean.listClass}"
                                                   itemLabel="${class.className}"
                                                   itemValue="${class.classId}" />
                                </h:selectOneMenu>

                            </h:panelGroup>

                            <h:selectOneMenu id="staff" style="width: 150px;" value="#{staffManagedBean.staffId}" title="Select Staff" rendered="true"
                                             >
                                <f:selectItem itemLabel="Select faculty" itemValue="" noSelectionOption="true"/>
                                <f:selectItems var="faculty" value="#{staffManagedBean.all}"
                                               itemLabel="${faculty.staffName}"
                                               itemValue="${faculty.staffId}" />
                            </h:selectOneMenu>

                        </h:panelGrid>
                    </h:panelGrid>



                    <h:commandButton value="view" action="#{marksManagedBean.addStudentMarkForm(marksManagerManagedBean.classId, marksManagerManagedBean.examinationId, staffManagedBean.staffId)}" >


                    </h:commandButton>
                </h:form>

                <h:form prependId="false" styleClass="form panel" style="min-height:280px;" id="formviewmark">

<!--                    <p:dataTable id="viewmark" var="student" value="#{marksManagedBean.layListStudentByClassId(marksManagerManagedBean.classId)}"
                                 paginator="false" rows="10"
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                                 rowsPerPageTemplate="1">

                        <p:column>
                            <f:facet name="header">Student RollNo</f:facet>
                            <h:outputText value="#{student.studentRollNo}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Student Name</f:facet>
                            <h:outputText value="#{studentManagedBean.layStudentByRollNo(student.studentRollNo).studentName}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Mark"/>
                            </f:facet>
                            <h:inputText style="width: 50px;" value="#{marksManagerManagedBean.mark}"/>
                            <h:commandButton value="ok" action="#{marksManagerManagedBean.addMark(marksManagerManagedBean.examinationId, staffManagedBean.staffId, student.studentRollNo, marksManagerManagedBean.mark)}" >

                            </h:commandButton>
                        </p:column>

                    </p:dataTable>-->

                    <p:dataTable id="viewmark2" var="student" value="#{marksManagedBean.layListStudentMarks(marksManagerManagedBean.classId, marksManagerManagedBean.examinationId)}"
                                 paginator="false" rows="30"
                                 paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                                 rowsPerPageTemplate="1">

                        <p:column>
                            <f:facet name="header">Subject Name</f:facet>
                            <h:outputText value="#{examinationManagedBean.layExamById(student.examId).examName}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Student RollNo</f:facet>
                            <h:outputText value="#{student.studentRollNo}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">Student Name</f:facet>
                            <h:outputText value="#{studentManagedBean.layStudentByRollNo(student.studentRollNo).studentName}" />
                        </p:column>
                        <p:column>
                            <f:facet name="header">MarkId </f:facet>
                            <h:outputText value="#{student.markId}" />
                        </p:column>

                        <p:column>
                            <f:facet name="header">
                                <h:outputText value="Mark"/>
                            </f:facet>
                            <p:inputText style="width: 50px;" value="#{student.mark}" >
                                <f:convertNumber pattern="" />
                            </p:inputText>
                        </p:column>

                        <p:column>
                            <f:facet name="header">OK</f:facet>
                            <h:commandButton value="ok" action="#{marksManagedBean.editStudentMarkForm(student.markId, student.mark)}" >
                                <f:setPropertyActionListener target="#{marksManagedBean.markEdited}" value="${student.mark}"></f:setPropertyActionListener>
                            </h:commandButton>
                        </p:column>
                    </p:dataTable>


                    <h:commandButton value="send request to teacher" action="results" />
                </h:form>


            </ui:define>

        </ui:composition>

    </body>
</html>
